//
//  NoDataCell.m
//  xWeibo
//
//  Created by alvis mac on 11/8/15.
//  Copyright © 2015 alvis. All rights reserved.
//

#import "NoDataCell.h"
#import "AyDefine.h"
#import "UIImageExtend.h"

#define kHeight 180

@interface NoDataCell()
{
    UIImageView *_bg;
    UIImageView *_icon;
    UILabel *_label;
    
    UIButton *_loadingBtn;
}
@end


@implementation NoDataCell

+ (instancetype) noDataCellWithUITableView:(UITableView *) table{
   static NSString * CID=@"nocell";
    NoDataCell *cell= [table dequeueReusableCellWithIdentifier:CID];
    if (cell==nil) {
        cell=[[self alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CID];
    }
    return cell;
}


- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.userInteractionEnabled = NO;
        // 1.背景
        CGFloat bgX = kTableBorderPadding;
        CGFloat bgWidth = self.frame.size.width - 2 * bgX;
        _bg = [[UIImageView alloc] init];
        _bg.image = [UIImage resizedImageWithName:@"statusdetail_comment_background_bottom.png"];
        _bg.frame = CGRectMake(bgX, 0, bgWidth, kHeight);
        _bg.hidden = YES;
        [self.contentView addSubview:_bg];
        
        // 2.图标
        _icon = [[UIImageView alloc] init];
        _icon.frame = CGRectMake(0, 0, bgWidth, kHeight * 0.6);
        _icon.contentMode = UIViewContentModeBottom;
        [_bg addSubview:_icon];
        
        // 3.文字
        CGFloat font = 15;
        _label = [[UILabel alloc] init];
        _label.font = [UIFont systemFontOfSize:font];
        _label.frame = CGRectMake(0, CGRectGetMaxY(_icon.frame), bgWidth, font + 5);
        _label.textAlignment = NSTextAlignmentCenter;
        _label.textColor = AyColor(189, 189, 189);
        _label.backgroundColor = [UIColor clearColor];
        [_bg addSubview:_label];
        
        // 4.正在加载
        _loadingBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [_loadingBtn setBackgroundImage:_bg.image forState:UIControlStateNormal];
        _loadingBtn.frame = CGRectMake(bgX, 0, bgWidth, kHeight);
        [_loadingBtn setTitle:@"正在帮你加载中..." forState:UIControlStateNormal];
        [_loadingBtn setTitleColor:AyColor(189, 189, 189) forState:UIControlStateNormal];
        [self.contentView addSubview:_loadingBtn];
    }
    return self;
}

- (void)setImageName:(NSString *)name
{
    _icon.image = [UIImage imageNamed:name];
}

- (void)setText:(NSString *)text
{
    _label.text = text;
}

- (void)setLoading:(BOOL)loading
{
    _loadingBtn.hidden = !loading;
    _bg.hidden = loading;
}

- (void)setFrame:(CGRect)frame{
    frame.origin.x = AyStatusTableBorder+2;
    frame.size.width -= 2 * (AyStatusTableBorder+2);
    [super setFrame:frame];
}

@end
